package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.TravelQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 甘静斌 on 2020-08-09 19:37
 */
@Controller
@RequestMapping("travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IDestinationService destinationService;

    /**
     * 游记管理分页
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo){

        Page<Travel> page = travelService.query(qo);
        model.addAttribute("page",page );

        return "/travel/list";
    }

    /**
     * 后端管理旅游日记页面,审核状态
     * @param id
     * @param state
     * @return
     */
    @RequestMapping("/audit")
    @ResponseBody
    public Object audit(String id,int state){

        travelService.changeState(id,state);
        return JsonResult.success();
    }


    /**
     * 模态框下拉框查询目的地
     * @return
     */
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests(){
        List<Destination> list = destinationService.list();
        return list;
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(long deep){
        List<Destination> list = destinationService.list(deep);
        return list;
    }

    //游记管理,下架功能
    @RequestMapping("/updateState")
    @ResponseBody
    public Object updateState(String id,int state){

        travelService.updateState(id,state);
        return JsonResult.success();
    }

    //游记管理,查看功能
    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id){

        Travel travel = travelService.get(id);
        return JsonResult.success(travel.getContent());
    }


}
